
import tkinter as tk
from doctor_info import *
from personal_center import *
from AppointmentApp import *

root=tk.Tk()

root.title('医院管理系统')
root.geometry('1920x1080')
root.configure(bg='#92CEDF')
#################################################################################患者界面
def show_personal_center():
    # 定义患者信息的变量
    patient_name = tk.StringVar()
    patient_age = tk.StringVar()
    patient_gender = tk.StringVar()
    patient_allergy = tk.StringVar()

    # 读取患者信息的函数
    def read_patient_info():
        try:
            with open('patient_info.txt', 'r') as f:
                patient_name.set(f.readline().strip())
                patient_age.set(f.readline().strip())
                patient_gender.set(f.readline().strip())
                patient_allergy.set(f.readline().strip())
        except:
            pass

    # 保存患者信息的函数
    def save_patient_info():
        with open('patient_info.txt', 'w') as f:
            f.write(patient_name.get()+'\n')
            f.write(patient_age.get()+'\n')
            f.write(patient_gender.get()+'\n')
            f.write(patient_allergy.get()+'\n')
        tk.messagebox.showinfo('提示', '保存成功！')


    # 展示个人信息的函数
    def show_patient_info():
        # 创建新的窗口及颜色
        info_window = tk.Toplevel(window)
        info_window.title('个人信息')
        info_window.configure(bg='#92CEDF')

        # 调整窗口大小并居中
        info_window.geometry('600x400')
        info_window.update_idletasks()  # 更新窗口的大小和位置信息
        x = (info_window.winfo_screenwidth() - info_window.winfo_reqwidth()) // 2
        y = (info_window.winfo_screenheight() - info_window.winfo_reqheight()) // 2
        info_window.geometry(f"+{x}+{y}")

        # 读取患者信息
        read_patient_info()

        # 创建标签和展示框
        tk.Label(info_window, text='姓名：',font=('黑体', 20), bg='#92CEDF', fg='gray').pack(padx=5, pady=5, anchor='w')
        tk.Label(info_window, textvariable=patient_name,font=('黑体', 20), bg='#92CEDF', fg='#FFFFFF').pack(padx=5, pady=5, anchor='w')

        tk.Label(info_window, text='年龄：',font=('黑体', 20), bg='#92CEDF', fg='gray').pack(padx=5, pady=5, anchor='w')
        tk.Label(info_window, textvariable=patient_age,font=('黑体', 20), bg='#92CEDF', fg='#FFFFFF').pack(padx=5, pady=5, anchor='w')

        tk.Label(info_window, text='性别：',font=('黑体', 20), bg='#92CEDF', fg='gray').pack(padx=5, pady=5, anchor='w')
        tk.Label(info_window, textvariable=patient_gender,font=('黑体', 20), bg='#92CEDF', fg='#FFFFFF').pack(padx=5, pady=5, anchor='w')

        tk.Label(info_window, text='药物过敏史：',font=('黑体', 20), bg='#92CEDF', fg='gray').pack(padx=5, pady=5, anchor='w')
        tk.Label(info_window, textvariable=patient_allergy,font=('黑体', 20), bg='#92CEDF', fg='#FFFFFF').pack(padx=5, pady=5, anchor='w')

    # 读取患者信息
    read_patient_info()

    # 创建窗口和标签
    window = tk.Toplevel(root)
    window.title('个人中心')

    # 调整窗口大小并居中
    window.geometry('1920x1080')

    # 计算窗口的中心位置
    info_window_width = root.winfo_screenwidth()
    info_window_height = root.winfo_screenheight()
    x = (info_window_width - 1920) // 2
    y = (info_window_height - 1080) // 2
    window.geometry(f"1920x1080+{x}+{y}")

    # 修改窗口背景颜色和字体颜色
    window.configure(bg='#92CEDF')
    tk.Label(window, text='个人中心', font=('仿宋', 60, 'bold'), bg='#92CEDF', fg='#FFFFFF',
             highlightbackground='#92CEDF', highlightthickness=0).pack(pady=50)

    # 创建姓名标签和输入框
    name_frame = tk.Frame(window, bg='#92CEDF', highlightbackground='#92CEDF', highlightthickness=0)
    name_frame.pack(padx=10, pady=(50, 10), anchor='w')

    tk.Label(name_frame, text='姓名：', font=('黑体', 50), bg='#92CEDF', fg='#FFFFFF', width=10).pack(side='left')

    entry_default_text = '请输入名字'
    patient_name = tk.StringVar()
    patient_name.set(entry_default_text)

    entry = tk.Entry(name_frame, textvariable=patient_name, font=('黑体', 50), bg='white', fg='#3C8DF8',
                     highlightbackground='#3C8DF8', highlightthickness=0, width=15)
    entry.pack(side='left', padx=170)

    def on_entry_focus_in(event):
        if entry.get() == entry_default_text:
            entry.delete(0, tk.END)
            entry.configure(show='')

    def on_entry_focus_out(event):
        if entry.get() == '':
            entry.configure(show='*')
            entry.insert(0, entry_default_text)

    entry.bind('<FocusIn>', on_entry_focus_in)
    entry.bind('<FocusOut>', on_entry_focus_out)

    # 创建性别标签和选项
    gender_frame = tk.Frame(window, bg='#92CEDF', highlightbackground='#92CEDF', highlightthickness=0)
    gender_frame.pack(padx=80, pady=(10, 50), anchor='w')

    tk.Label(gender_frame, text='性别：', font=('黑体', 50), bg='#92CEDF', fg='#FFFFFF').pack(side='left')

    gender_options = tk.Frame(gender_frame, bg='#92CEDF', highlightbackground='#92CEDF', highlightthickness=0)
    gender_options.pack(side='left', padx=185)

    male_var = tk.StringVar()
    male_checkbtn = tk.Checkbutton(gender_options, text='男', variable=male_var, font=('黑体', 50), bg='#92CEDF',
                                   fg='#FFFFFF', selectcolor='', indicatoron=False)
    male_checkbtn.pack(side='left', padx=50)

    female_var = tk.StringVar()
    female_checkbtn = tk.Checkbutton(gender_options, text='女', variable=female_var, font=('黑体', 50), bg='#92CEDF',
                                     fg='#FFFFFF', selectcolor='', indicatoron=False)
    female_checkbtn.pack(side='left', padx=100)

    # 创建年龄标签和输入框
    age_frame = tk.Frame(window, bg='#92CEDF', highlightbackground='#92CEDF', highlightthickness=0)
    age_frame.pack(padx=80, pady=(10, 50), anchor='w')

    tk.Label(age_frame, text='年龄：', font=('黑体', 50), bg='#92CEDF', fg='#FFFFFF').pack(side='left')

    tk.Entry(age_frame, textvariable=patient_age, font=('黑体', 50), bg='white', fg='#3C8DF8',
             highlightbackground='#3C8DF8', highlightthickness=0).pack(side='left', padx=235)

    # 创建药物过敏史标签和输入框
    allergy_frame = tk.Frame(window, bg='#92CEDF', highlightbackground='#92CEDF', highlightthickness=0)
    allergy_frame.pack(padx=10, pady=(10, 10), anchor='w')

    tk.Label(allergy_frame, text='药物过敏史：', font=('黑体', 50), bg='#92CEDF', fg='#FFFFFF').pack(side='left')

    tk.Entry(allergy_frame, textvariable=patient_allergy, font=('黑体', 50), bg='white', fg='#3C8DF8',
             highlightbackground='#3C8DF8', highlightthickness=0).pack(side='left', padx=100)

    # 创建保存按钮和查看按钮
    tk.Button(window, text='保存', font=('黑体', 40),bg='#3C8DF8',fg='#FFFFFF',command=save_patient_info).pack(side='left', padx=250, pady=5)
    tk.Button(window, text='查看', font=('黑体', 40),bg='#3C8DF8',fg='#FFFFFF',command=show_patient_info).pack(side='left', padx=500, pady=5)

welcome_label = tk.Label(root, text='欢迎进入医院挂号系统!', font=('仿宋', 60, 'bold'), bg='#92CEDF', fg='#FFFFFF', highlightbackground='#92CEDF', highlightthickness=0)
welcome_label.pack(pady=100)

# 创建首页按钮
doctor_btn = tk.Button(root, text='医生信息', font=('黑体', 40, 'bold'), fg='#3C8DF8', command=show_doctor_info, pady=30, highlightbackground='#CCCCCC', highlightthickness=2)
doctor_btn.pack(pady=40)

personal_btn = tk.Button(root, text='个人中心', font=('黑体', 40, 'bold'), fg='#3C8DF8', command=show_personal_center, pady=30, highlightbackground='#CCCCCC', highlightthickness=2)
personal_btn.pack(pady=40)

appointment_btn = tk.Button(root, text='预约挂号', font=('黑体', 40, 'bold'), command=show_appointment, fg='#3C8DF8', pady=30, highlightbackground='#CCCCCC', highlightthickness=2)
appointment_btn.pack(pady=40)

#运行主程序
root = tk.Tk()
root.geometry("5x5")
#######################################################################医生界面
def show_doctor_info():
    window = tk.Toplevel(root)
    window.title('医生信息')

    # 调整窗口大小
    window.geometry('1920x1080')

    # 计算窗口的中心位置
    window_width = root.winfo_screenwidth()
    window_height = root.winfo_screenheight()
    x = (window_width - 1920) // 2
    y = (window_height - 1080) // 2
    window.geometry(f"1920x1080+{x}+{y}")

    # 修改窗口背景颜色和字体颜色
    window.configure(bg='#92CEDF')
    tk.Label(window, text='医生信息', font=('仿宋', 60, 'bold'), bg='#92CEDF', fg='#FFFFFF', highlightbackground='#92CEDF', highlightthickness=0).pack(pady=50)

    # 创建滚动条和表格容器
    scroll_canvas = tk.Canvas(window, bg='#92CEDF')
    scroll_canvas.pack(side='top', fill='x', padx=20, pady=(0, 50))

    # 创建滚动条
    scrollbar = tk.Scrollbar(window, orient='vertical', command=scroll_canvas.yview)
    scrollbar.pack(side='right', fill='y')

    # 绑定滚动条与表格容器
    scroll_canvas.configure(yscrollcommand=scrollbar.set)
    scroll_canvas.bind('<Configure>', lambda e: scroll_canvas.configure(scrollregion=scroll_canvas.bbox('all')))

    # 创建表格
    table = tk.Frame(scroll_canvas, bg='#92CEDF')

    scroll_canvas.create_window((0, 0), window=table, anchor='nw')

    # 表头
    header = tk.Frame(table, bg='#FFFFFF')
    header.pack(fill='x')
    name_label = tk.Label(header, text='姓名', font=('黑体', 50, 'bold'), bg='#FFFFFF', fg='#3C8DF8', highlightbackground='#FFFFFF', highlightthickness=0, width=10)
    name_label.pack(side='left', padx=40, pady=50)
    age_label = tk.Label(header, text='年龄', font=('黑体', 50, 'bold'), bg='#FFFFFF', fg='#3C8DF8', highlightbackground='#FFFFFF', highlightthickness=0, width=10)
    age_label.pack(side='left', padx=40, pady=50)
    department_label = tk.Label(header, text='科室', font=('黑体', 50, 'bold'), bg='#FFFFFF', fg='#3C8DF8', highlightbackground='#FFFFFF', highlightthickness=0, width=10)
    department_label.pack(side='left', padx=40, pady=50)
    specialty_label = tk.Label(header, text='擅长方向', font=('黑体', 50, 'bold'), bg='#FFFFFF', fg='#3C8DF8', highlightbackground='#FFFFFF', highlightthickness=0, width=20)
    specialty_label.pack(side='left', padx=40, pady=50)


    # 医生信息
    doctors = [
        {'name': '张三', 'age': 35, 'department': '内科', 'specialty': '心脏病'},
        {'name': '李四', 'age': 40, 'department': '外科', 'specialty': '创伤，感染'},
        {'name': '王五', 'age': 30, 'department': '内科', 'specialty': '感冒，发烧'}
    ]
    for i, doctor in enumerate(doctors):
        row = tk.Frame(table, bg='#92CEDF' if i < 3 else '#92CEDF80')
        row.pack(fill='x')
        name = tk.Label(row, font=('黑体', 50,), text=doctor['name'], width=10, bg='#92CEDF' if i < 3 else '#92CEDF80',
                        highlightbackground='#92CEDF', highlightthickness=0.8)
        name.pack(side='left', padx=40, pady=30)
        age = tk.Label(row, text=doctor['age'], font=('黑体', 50,), width=10, bg='#92CEDF' if i < 3 else '#92CEDF80',
                       highlightbackground='#92CEDF', highlightthickness=0.8)
        age.pack(side='left', padx=40, pady=30)
        department = tk.Label(row, text=doctor['department'], font=('黑体', 50,), width=10,
                              bg='#92CEDF' if i < 3 else '#92CEDF80', highlightbackground='#92CEDF',
                              highlightthickness=0.8)
        department.pack(side='left', padx=40, pady=30)
        specialty = tk.Label(row, text=doctor['specialty'], font=('黑体', 50,), width=20,
                             bg='#92CEDF' if i < 3 else '#92CEDF80', highlightbackground='#92CEDF',
                             highlightthickness=0.8)
        specialty.pack(side='left', padx=40, pady=30)

        # 为每个医生信息行绑定点击事件
        row.bind('<Button-1>', lambda event, name=doctor['name']: show_doctor_detail(name))

    # 创建底部边框
    bottom_border = tk.Frame(table, bg='#FFFFFF', height=1)
    bottom_border.pack(fill='x')

    # 设置表格容器的大小
    table.update_idletasks()
    scroll_canvas.configure(scrollregion=scroll_canvas.bbox('all'), width=table.winfo_width(), height=600)



    # 生成随机上班时间
    def get_doctor_work_schedule(name):
        start_hour = random.randint(8, 10)
        end_hour = random.randint(15, 18)
        return f'{start_hour}:00 - {end_hour}:00'

    # 在show_doctor_detail函数中使用随机上班时间
    def show_doctor_detail(name=doctor['name']):
        # 创建医生详情窗口
        detail_window = tk.Toplevel(window)
        detail_window.title(f'{name}详情')

        # 设置窗口背景颜色和大小
        detail_window.configure(bg='#92CEDF')
        detail_window.geometry('400x100')

        # 让窗口居中显示
        detail_window.update_idletasks()
        window_width = detail_window.winfo_screenwidth()
        window_height = detail_window.winfo_screenheight()
        x = (window_width - detail_window.winfo_width()) // 2
        y = (window_height - detail_window.winfo_height()) // 2
        detail_window.geometry(f"+{x}+{y}")

        # 创建医生详细信息标签
        detail_label = tk.Label(detail_window, text=f'{name}的详细信息', font=('仿宋', 24, 'bold'), bg='#92CEDF',fg='#FFFFFF')
        detail_label.pack(padx=10, pady=10)
        # 获取医生上班时间
        work_schedule = get_doctor_work_schedule(name)
        # 创建医生上班时间标签
        schedule_label = tk.Label(detail_window, text=f'上班时间：{work_schedule}', font=('仿宋', 18), bg='#92CEDF',fg='#FFFFFF')
        schedule_label.pack(padx=10, pady=10)
####################################################### 预约页面

class AppointmentApp:
    def __init__(self):
        def show_appointment():
            appointment_app = AppointmentApp()

        self.window = tk.Toplevel(root)
        self.window.title('预约')

        # 调整窗口大小并居中
        self.window.geometry('1920x1080')
        self.window.update_idletasks()

        # 计算窗口的中心位置
        window_width = root.winfo_screenwidth()
        window_height = root.winfo_screenheight()
        x = (window_width - 1920) // 2
        y = (window_height - 1080) // 2
        self.window.geometry(f"1920x1080+{x}+{y}")

        # 修改窗口背景颜色和字体颜色
        self.window.configure(bg='#92CEDF')
        tk.Label(self.window, text='预约挂号', font=('仿宋', 60, 'bold'), bg='#92CEDF', fg='#FFFFFF',
                 highlightbackground='#92CEDF', highlightthickness=0).pack(pady=50)

        # 创建症状标签和输入框
        symptom_frame = tk.Frame(self.window, bg='#92CEDF', highlightbackground='#92CEDF', highlightthickness=0)
        symptom_frame.pack(padx=10, pady=(50, 80), anchor='w')

        tk.Label(symptom_frame, text='症状：', font=('黑体', 50), bg='#92CEDF', fg='#FFFFFF', width=10).pack(side='left')

        self.symptom_entry = tk.Entry(symptom_frame, font=('黑体', 50), bg='white', fg='#3C8DF8',
                                      highlightbackground='#3C8DF8', highlightthickness=0, width=15)
        self.symptom_entry.pack(side='left', padx=140)
        # 创建时间段标签和选项
        time_frame = tk.Frame(self.window, bg='#92CEDF', highlightbackground='#92CEDF', highlightthickness=0)
        time_frame.pack(padx=80, pady=(10, 100), anchor='w')

        tk.Label(time_frame, text='时间段：', font=('黑体', 50), bg='#92CEDF', fg='#FFFFFF').pack(side='left')

        # 假设这里的available_times是一个包含可供选择的时间段的列表
        available_times = ['上午9点-10点', '下午2点-3点', '下午4点-5点']

        self.time_var = tk.StringVar(self.window)
        self.time_var.set(available_times[0])  # 设置默认选择第一个时间段

        time_dropdown = tk.OptionMenu(time_frame, self.time_var, *available_times)
        time_dropdown.config(font=('黑体', 50), bg='#92CEDF', fg='#FFFFFF')
        # 获取内部的Menu小部件
        menu = time_dropdown["menu"]
        # 遍历所有菜单项，并设置字体大小
        for index in range(len(available_times)):
            menu.entryconfig(index, font=('黑体', 20))

        time_dropdown.pack(padx=140)

        # 创建诊室标签和选项
        room_frame = tk.Frame(self.window, bg='#92CEDF', highlightbackground='#92CEDF', highlightthickness=0)
        room_frame.pack(padx=80, pady=(10, 100), anchor='w')

        tk.Label(room_frame, text='诊室：', font=('黑体', 50), bg='#92CEDF', fg='#FFFFFF').pack(side='left')

        # 假设这里的available_rooms是一个包含可供选择的诊室的列表
        available_rooms = ['内科', '外科', '儿科']

        self.room_var = tk.StringVar(self.window)
        self.room_var.set(available_rooms[0])  # 设置默认选择第一个诊室

        room_dropdown = tk.OptionMenu(room_frame, self.room_var, *available_rooms)
        room_dropdown.config(font=('黑体', 50), bg='#92CEDF', fg='#FFFFFF')

        # 获取内部的Menu小部件
        menu = room_dropdown['menu']

        # 遍历所有菜单项，并设置字体大小
        for index in range(len(available_rooms)):
            menu.entryconfig(index, font=('黑体', 20))

        room_dropdown.pack(side='left', padx=210)

        submit_button = tk.Button(self.window, text='提交预约', font=('黑体', 40), bg='#3C8DF8', fg='#FFFFFF',
                                  command=self.submit_appointment)
        submit_button.pack()

    def submit_appointment(self):
        symptom = self.symptom_entry.get()
        time = self.time_var.get()
        room = self.room_var.get()

        # 在这里执行提交预约的操作，将患者输入的症状(symptom)、选择的时间段(time)和诊室(room)保存到文档中
        # 可以使用这些信息来生成预约记录或者与数据库进行交互等操作
        # 这里只是示例，你可以根据实际需求进行相应的处理

        # 打开文件，以追加模式写入预约信息
        with open('appointments.txt', 'a') as file:
            file.write(f'症状：{symptom}\n')
            file.write(f'时间段：{time}\n')
            file.write(f'诊室：{room}\n')
            file.write('\n')  # 写入空行作为分隔符

        # 提示预约信息保存成功
            messagebox.showinfo('预约', '预约信息已保存成功。')

        # 清空输入框中的内容
        self.symptom_entry.delete(0, tk.END)
# 计算窗口的中心位置
window_width = root.winfo_screenwidth()
window_height = root.winfo_screenheight()
x = (window_width - 1920) // 2
y = (window_height - 1080) // 2
root.geometry(f"5x5+{x}+{y}")
root.mainloop()